//
//  ZDDStatusRetweetView.swift
//  小蜗牛_新浪微博
//
//  Created by 周冬冬 on 16/6/29.
//  Copyright © 2016年 我的mac. All rights reserved.
//

import UIKit
import SnapKit
class ZDDStatusRetweetView: UIView {
var retweetViewBottomConstraint: Constraint?
    var status:ZDDStatuses?{
    
        didSet{
        
        contentLabel.text = status?.retweeted_status?.text
        
            retweetViewBottomConstraint?.uninstall()
            
            if status?.retweeted_status?.pic_urls?.count > 0{
            
                pictureView.hidden = false
                
                //赋值
                pictureView.pic_urls = status?.retweeted_status?.pic_urls
                self.snp_makeConstraints(closure: { (make) -> Void in
                    retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(StautsMargin).constraint
                })
                
            
            }else{
            
                pictureView.hidden = true
                self.snp_makeConstraints(closure: { (make) -> Void in
                    retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(StautsMargin).constraint
                })
            }
            
            
        }
    
    
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
  
    private func setupUI(){
    
         backgroundColor = RBG(237,green: 237,blue: 237)
        //添加控件
        addSubview(contentLabel)
        addSubview(pictureView)
        //添加约束
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.leading.equalTo(self).offset(StautsMargin)
        //配图
        pictureView.snp_makeConstraints(closure: { (make) -> Void in
            make.size.equalTo(CGSize(width: 100, height: 100))
            make.top.equalTo(contentLabel.snp_bottom).offset(StautsMargin)
            make.leading.equalTo(contentLabel)
        })
        self.snp_makeConstraints(closure: { (make) -> Void in
          retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(StautsMargin).constraint
        })
        }
    
    
    }
    private lazy var contentLabel:UILabel = UILabel(textColor: UIColor.blackColor(), textFont: 15, MaxWith: kScreenW - 2 * StautsMargin)
    private lazy var pictureView : ZDDPictureInfo = ZDDPictureInfo()
}
